package com.liuxin.zhiyuan.user.controller;


import com.liuxin.common.utils.R;
import com.liuxin.common.utils.UserContext;
import com.liuxin.zhiyuan.user.domain.dto.LoginFormDTO;
import com.liuxin.zhiyuan.user.domain.vo.UserLoginVO;
import com.liuxin.zhiyuan.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController // 登录相关接口的控制器
@RequestMapping("/user/login") // 登录相关接口
@RefreshScope // 实时刷新配置信息，无需重启服务
@RequiredArgsConstructor // 自动注入构造函数中的所有final字段
public class UserLoginController {

    private final UserService userService;

    @PostMapping("loginWithPhoneAndPwd")
    public R loginWithPhoneAndPwd(@RequestBody @Validated LoginFormDTO loginFormDTO){
        UserLoginVO login;
        try {
            login = userService.login(loginFormDTO);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
        return R.ok().put("data", login);
    }
}






